require 'statistic/html_fields_counter'
require "rexml/document"

module Statistic
  
  class StumbleuponFieldsCounter < HTMLFieldsCounter
    
    public
    
    def initialize( crawl_table, conditions = "status = 200" )
      super crawl_table, conditions
    end
    
    
    def analyse_html(xml_tree)
      
      matches = REXML::XPath.match xml_tree, "/html/body/div[@id='wrapper']/div[@id='wrapperContent']/div[@id='content']/div/div/p[@class = 'userInfo'][contains(text(),'year old')]"
      @fields_stat["age"] += 1 if matches.length != 0
      
      matches = REXML::XPath.match xml_tree, "/html/body/div[@id='wrapper']/div[@id='wrapperContent']/div[@id='content']/div/div/p[@class = 'userInfo'][contains(text(),'man') or contains(text(),'woman')]"
      @fields_stat["gender"] += 1 if matches.length != 0
      
      #informazioni sul dove si trova o è nato (investigare emglio i detagli)
      matches = REXML::XPath.match xml_tree, "/html/body/div[@id='wrapper']/div[@id='wrapperContent']/div[@id='content']/div/div/p/a"
      matches.each {|e| @fields_stat[e.attribute('href').value.split('/')[1]] += 1}  
    end    
  end
  
end